package com.yanxu.design01_singleton.destroy.reflection_destory;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/4/14-2025
 * @Description: 这里用一句话描述这个类的作用
 */
public class LazyTest {
    public static void main1(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        LazyInstance instance = LazyInstance.getInstance();
        System.out.println("LazyInstance instance = " + instance);

        Class<LazyInstance> lazyInstanceClass = LazyInstance.class;;
        Constructor<LazyInstance> constructor = lazyInstanceClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        LazyInstance lazyInstance2 = constructor.newInstance();
        System.out.println("LazyInstance instance = " + lazyInstance2);

        System.out.println(instance==lazyInstance2);
    }

    public static void main2(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        LazyInstance_Fixed instance = LazyInstance_Fixed.getInstance();
        System.out.println("LazyInstance instance = " + instance);

        Class<LazyInstance_Fixed> lazyInstanceClass = LazyInstance_Fixed.class;
        Constructor<LazyInstance_Fixed> constructor = lazyInstanceClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        LazyInstance_Fixed lazyInstance2 = constructor.newInstance();
        System.out.println("LazyInstance instance = " + lazyInstance2);

        System.out.println(instance==lazyInstance2);
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {

        Class<LazyInstance_Fixed> lazyInstanceClass = LazyInstance_Fixed.class;
        Constructor<LazyInstance_Fixed> constructor = lazyInstanceClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        LazyInstance_Fixed lazyInstance2 = constructor.newInstance();
        System.out.println("LazyInstance instance = " + lazyInstance2);

        LazyInstance_Fixed instance = LazyInstance_Fixed.getInstance();
        System.out.println("LazyInstance instance = " + instance);

        System.out.println(instance==lazyInstance2);
    }

}